<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>012-属性的判断.html</title>
</head>
<body>
	
</body>
<script>
	function Person(name,age){
		this.name = name;
		this.age = age;
	}
	Person.prototype.showName = function(){
		console.log("I am"+this.name);
	}
	Person.prototype.showAge = function(){
		console.log("I am"+this.age+"years old");
	}
	Person.prototype.LEGS =2;

	var p1 = new Person("chris",22);
/*
	if(p1.name){
		console.log(p1.name);
	}else{
		console.log('nothing...');
	}
*/
	if(p1.hasOwnProperty('name')){
		console.log(p1.name);
	}else{
		console.log('nothing...');
	}
		console.log(p1.LEGS);
	if(p1.hasOwnProperty('LEGS')){
		console.log(p1.LEGS);
	}else{
		console.log('nothing...');
	}
	if('LEGS' in p1){
		console.log(p1.LEGS);
	}else{
		console.log('nothing...');
	}
	if('name' in p1){
		console.log(p1.name);
	}else{
		console.log('nothing...');
	}

	if(hasOwnPrototype(p1,'LEGS')){
		console.log(p1.LEGS);
	}
	if(hasOwnPrototype(p1,'name')){
		console.log(p1.name);
	}
	function hasOwnPrototype(obj,attr){
		return !obj.hasOwnProperty(attr) && (attr in obj)
	}
	/*
 	function isInPrototype(obj,attr){
 		return !obj.hasOwnProperty(attr)&&(attr in obj);
 	}
 	console.log(isInPrototype(p1."name"));
 	console.log(isInPrototype(p1."age"));
 	console.log(isInPrototype(p1."LEGS"));
 	*/
</script>
</html>